package MapApi;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class GetMap {
    /*
    | V   get(Object key)              | 根据键获取值             |
    | -------------------------------- | ------------------------ |
    | Set<K>   keySet()                | 获取所有键的集合         |
    | Collection<V>   values()         | 获取所有值的集合         |
    | Set<Map.Entry<K,V>>   entrySet() | 获取所有键值对对象的集合 |
     */
    public static void main(String[] args) {
        Map<String,String> map=new HashMap<>();

        map.put("德莉莎","花lin");
        map.put("张无忌","赵敏");
        map.put("郭靖","黄蓉");
        map.put("杨过","小龙女");


        Set<String> strings = map.keySet();
        //使用增强for
        for (String string : strings) {
            String value = map.get(string);
            System.out.println(string+"="+value);
        }
        System.out.println("====================================");
        //使用迭代器
        Iterator<String> iterator = strings.iterator();
        while (iterator.hasNext()){
            String key = iterator.next();
            String value = map.get(key);
            System.out.println(key+"="+value);
        }
        System.out.println("====================================");
        //使用lambda表达式foreach
        strings.forEach(s->{
            String value = map.get(s);
            System.out.println(s+"="+value);
        });
    }
}
